// Copyright (c) 2010 Thomas Stuefe
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma managed(push, off)
#include "sqlite3.h"
#pragma managed(pop)

#include "ErrorCode.h"

namespace zencat {
namespace sqlite {


	// helper, returns an ErrorCode enum from an sqlite raw errcode (casting is kinda dangerous 
	// because more errorcodes might be added in the future and I cannot guarantee ErrorCode always
	// having all values).
	ErrorCode errorCodeFromRawCode(int raw) {

#define _X(code)  case code: return ErrorCode::EC_ ## code;
		switch (raw) {
			_X(SQLITE_OK)
			_X(SQLITE_ERROR)
			_X(SQLITE_INTERNAL)
			_X(SQLITE_PERM)
			_X(SQLITE_ABORT)
			_X(SQLITE_BUSY)
			_X(SQLITE_LOCKED)
			_X(SQLITE_NOMEM)
			_X(SQLITE_READONLY)
			_X(SQLITE_INTERRUPT)
			_X(SQLITE_IOERR)
			_X(SQLITE_CORRUPT)
			_X(SQLITE_NOTFOUND)
			_X(SQLITE_FULL)
			_X(SQLITE_CANTOPEN)
			_X(SQLITE_PROTOCOL)
			_X(SQLITE_EMPTY)
			_X(SQLITE_SCHEMA)
			_X(SQLITE_TOOBIG)
			_X(SQLITE_CONSTRAINT)
			_X(SQLITE_MISMATCH)
			_X(SQLITE_MISUSE)
			_X(SQLITE_NOLFS)
			_X(SQLITE_AUTH)
			_X(SQLITE_FORMAT)
			_X(SQLITE_RANGE)
			_X(SQLITE_NOTADB)
			_X(SQLITE_ROW)
			_X(SQLITE_DONE)
			_X(SQLITE_IOERR_READ)
			_X(SQLITE_IOERR_SHORT_READ)
			_X(SQLITE_IOERR_WRITE)
			_X(SQLITE_IOERR_FSYNC)
			_X(SQLITE_IOERR_DIR_FSYNC)
			_X(SQLITE_IOERR_TRUNCATE)
			_X(SQLITE_IOERR_FSTAT)
			_X(SQLITE_IOERR_UNLOCK)
			_X(SQLITE_IOERR_RDLOCK)
			_X(SQLITE_IOERR_DELETE)
			_X(SQLITE_IOERR_BLOCKED)
			_X(SQLITE_IOERR_NOMEM)
			_X(SQLITE_IOERR_ACCESS)
			_X(SQLITE_IOERR_CHECKRESERVEDLOCK)
			_X(SQLITE_IOERR_LOCK)
			_X(SQLITE_IOERR_CLOSE)
			_X(SQLITE_IOERR_DIR_CLOSE)
			_X(SQLITE_IOERR_SHMOPEN)
			_X(SQLITE_IOERR_SHMSIZE)
			_X(SQLITE_IOERR_SHMLOCK)
			_X(SQLITE_LOCKED_SHAREDCACHE)
			_X(SQLITE_BUSY_RECOVERY)
			_X(SQLITE_CANTOPEN_NOTEMPDIR)
			default: return ErrorCode::EC_UNKNOWN;
		}

#undef _X

	} // end: errorCodeFromRawCode

} // end namespace sqlite

} // end namespace zencat